﻿using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public class GameOverView : MonoBehaviour
{

    public GameObject Tittle;
    public Text TittleText;
    public GameObject Info;
    public Text InfoText;
	public Button ReplayBtn;

	// Use this for initialization
	void OnEnable ()
	{
	    TittleText.text = MapData.Instance.TargetsSuccessNum >= Const.TargetNum ? "挑战成功" : "游戏结束";
	    var nodeList = TreeData.Instance.AllTreeParts.FindAll(data => data.Type == TreePartType.Node);
	    InfoText.text = string.Format("树的总高度是：{0}\n\n达成目标数：{1}/{2}", nodeList.Count, MapData.Instance.TargetsSuccessNum, Const.TargetNum);
	    Tittle.transform.DOLocalMoveX(0, 1f);
	    Info.transform.DOLocalMoveY(-80, 1f);

		ReplayBtn.onClick.AddListener(ReplayGame);
	}

	void ReplayGame()
	{
		PlayerData.Instance.Restart();
		UIScenenManager.getInstance ().openSceneUI ();
		UIManager.getInstance ().openDialog (new UIMain());
		GameObject.Destroy (gameObject);
	}

	// Update is called once per frame
	void Update () {
		
	}

    void Disappear(UnityAction callBack)
    {
        Tittle.transform.DOLocalMoveX(640, 0.5f);
        Info.transform.DOLocalMoveY(-750, 0.5f).OnComplete(() =>
        {
            if (callBack != null) callBack.Invoke();
        });
    }
}
